package org.eproject.core.well.factory;

import java.util.HashMap;
import java.util.Map;

import org.eproject.core.well.exception.FactoryException;

public class Simplefactory {
	private static Map<String,Object> doCache = new HashMap<String, Object>();

	public static <T> T creatorBean(String beanname) throws FactoryException{
		if (doCache.containsKey(beanname))
			return (T) doCache.get(beanname);
		Map<String,String> configXml = Readconfig.getXmlConfig();
		String clname = configXml.get(beanname);
		try {
			Object temp = Class.forName(clname).newInstance();
			doCache.put(beanname,temp);
			return (T)temp;
		} catch (InstantiationException e) {
			e.printStackTrace();
			throw new FactoryException(e);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			throw new FactoryException(e);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new FactoryException(e);
		}
	}
}
